home *** CD-ROM | disk | FTP | other *** search
/ PCNet 2006 April / PCnet 2006-06.4.iso / shareware / nmsetup.exe / WebServer / web / image.php < prev    next >
Encoding:
PHP Script  |  2006-05-01  |  15.6 KB  |  418 lines

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // <!--Copyright (c) 2005 Pure Networks Inc.  All rights reserved.-->
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // Build: 3.0.6121.0 (Stable)
  7. // $Revision: #3 $
  8. //
  9.  
  10. $sNavLocation = "folders";
  11. $sNavPage = "details";
  12. $sLocation = "Shared Folders";
  13. require '_session_common.php';
  14.  
  15. ///////////////////////////////////////////////////
  16. // Make sure that we have a valid share passed in.
  17. ///////////////////////////////////////////////////
  18. if (!isset($_GET['share']))
  19. {
  20.     $errorOccurred = 200;
  21.     log_activity("QS check", "failure", return_error_text(200, "", $arErrors));
  22. }
  23. else
  24. {
  25.     $sShare = $_GET['share'];
  26.     log_activity("image share", "info", $sShare);
  27. }
  28. ///////////////////////////////////////////////////
  29. // Make sure that we have a valid path passed in.
  30. ///////////////////////////////////////////////////
  31. if ($errorOccurred == 0)
  32. {
  33.     if (!isset($_GET['path']))
  34.     {
  35.         $errorOccurred = 201;
  36.         log_activity("QS check", "failure", return_error_text(201, "", $arErrors));
  37.     }
  38.     else
  39.     {
  40.         $sPath = urlDecodeString($_GET['path']);
  41.         log_activity("image path", "info", $sPath);
  42.     }
  43. }
  44. require '_folderutils.php';
  45. /////////////////////////////////////////////////////////////////////////////////////////////////
  46. /////////////////////////////////////////////////////////////////////////////////////////////////
  47. // NOTE: we do several try catch blocks so we know exactly which function threw the exception. //
  48. /////////////////////////////////////////////////////////////////////////////////////////////////
  49. /////////////////////////////////////////////////////////////////////////////////////////////////
  50.  
  51. ///////////////////////////////////////////////////
  52. // Let's try to see if we can open the share
  53. ///////////////////////////////////////////////////
  54. try
  55. {
  56.     $nmSharedPlace  = $nmNetworkLib->OpenShare($sShare);
  57.     $sContainer     = $nmSharedPlace->ShareName;
  58.     $sUnc           = $nmSharedPlace->Unc;
  59. }
  60. catch(Exception $ex)
  61. {
  62.     log_activity("Attempting nmNetworkLib->OpenShare($sShare)", "exception", $ex->getMessage());
  63.     gotoAbs('/error/305/return');
  64.     exit();
  65. }
  66. ///////////////////////////////////////////////////
  67. // double check the access level and react
  68. ///////////////////////////////////////////////////
  69. try
  70. {
  71.     $sAccessLevel = $nmSharedPlace->AccessLevel;
  72. }
  73. catch(Exception $ex)
  74. {
  75.     log_activity("Attempting nmSharedPlace->AccessLevel", "exception", $ex->getMessage());
  76.     gotoAbs('/error/305/return');
  77.     exit();
  78. }
  79.  
  80. switch ($sAccessLevel)
  81. {
  82.     case 0:
  83.         ///////////////////////////////////////////////////
  84.         // Public share, show away.
  85.         ///////////////////////////////////////////////////
  86.         break;
  87.     case 1:
  88.         if (!$bLoggedIn)
  89.         {
  90.             ///////////////////////////////////////////////////
  91.             // Private share and user is not logged in, go away.
  92.             ///////////////////////////////////////////////////
  93.             log_activity("private folder request without session", "error", return_error_text(308, "", $arErrors));
  94.             gotoAbs('/login/308');
  95.             exit();
  96.         }
  97.         break;
  98.     case 2:
  99.         ///////////////////////////////////////////////////
  100.         // Restricted share, go away.
  101.         ///////////////////////////////////////////////////
  102.         log_activity("restricted share request", "error", return_error_text(310, "", $arErrors));
  103.         gotoAbs('/login/310');
  104.         exit();
  105.         break;
  106.     default:
  107.         log_activity("Undefined share access level", "error", return_error_text(311, "", $arErrors));
  108.         gotoAbs('/login/311');
  109.         exit();
  110. }
  111.  
  112. ///////////////////////////////////////////////////
  113. // Make sure that we have a valid fileName passed in.
  114. ///////////////////////////////////////////////////
  115. if ($errorOccurred == 0)
  116. {
  117.     if (!isset($_GET['fileName']))
  118.     {
  119.         $errorOccurred = 202;
  120.         log_activity("QS check", "failure", return_error_text(202, "", $arErrors));
  121.     }
  122.     else
  123.     {
  124.         $fileName = urlDecodeString($_GET['fileName']);
  125.  
  126.         // get the file arrays if needed
  127.         $sPath    = substr($sPath, 0, (strlen($sPath) - strlen($fileName) - 1));
  128.         createSessionFileArrays($sShare, $sPath, $sPath, $nmSharedPlace, false, $_GET['page']);
  129.         $arSharePath = $_SESSION['currentFolderInfo'];
  130.         $arFiles = $_SESSION['currentFolderFiles'];
  131.         //init variables
  132.         $count = count($arFiles);
  133.         $sWorkingPrev  = "";
  134.         $sFullFilePath = "";
  135.         $sPrevFilePath = "";
  136.         $sPrevFileName = "";
  137.         $sNextFilePath = "";
  138.         $sNextFileName = "";
  139.         $bGetNext      = false;
  140.         $bShowNextPrev = false;
  141.         if ($count > 1)
  142.         {
  143.             $bShowNextPrev = true;
  144.         }
  145.         
  146.         $iFileCounter = 1;
  147.         $sFirstFileName = "";
  148.         $bBreak = true;
  149.         foreach ($arFiles as $file)
  150.         {
  151.             // set the name of the very first file away in case we hit the end and want to next.
  152.             if ($iFileCounter == 1)
  153.             {
  154.                 $sFirstFileName = urlDecodeString($file[0]);
  155.             }
  156.  
  157.             if ($bGetNext)
  158.             {
  159.                 if ($bBreak)
  160.                 {
  161.                     $sNextFileName = urlDecodeString($file[0]);
  162.                     $bBreak = false;
  163.                     $bGetNext = false;
  164.                 }
  165.                 else
  166.                 {
  167.                     if ($iFileCounter == count($arFiles))
  168.                     {
  169.                         //we hit the end after finding the file, let's assign the last file to the prev
  170.                         $sPrevFileName = urlDecodeString($file[0]);
  171.                     }
  172.  
  173.                     if ($iFileCounter == 2)
  174.                     {
  175.                         $sNextFileName = urlDecodeString($file[0]);
  176.                     }
  177.                 }
  178.             }
  179.             if (urlDecodeString($file[0]) == $fileName)
  180.             {
  181.                 $sFullFilePath = $arSharePath[1] . "\\" . urlDecodeString($file[0]);
  182.                 $sPrevFileName = $sWorkingPrev;
  183.  
  184.                 if ($iFileCounter == count($arFiles))
  185.                 {
  186.                     // we hit the end of the array, next is actually the beginning
  187.                     $sNextFileName = $sFirstFileName;
  188.                 }
  189.                 else
  190.                 {
  191.                     $bGetNext = true;
  192.                 }
  193.  
  194.                 if ($iFileCounter == 1)
  195.                 {
  196.                     // we found our file and it's the first one in the array - show prev as last item
  197.                     $bBreak = false;
  198.                 }
  199.             }
  200.             $sWorkingPrev = urlDecodeString($file[0]);
  201.             $iFileCounter++;
  202.         }
  203.         $sPrevFilePath = $arSharePath[1] . "\\" . $sPrevFileName;
  204.         $sNextFilePath = $arSharePath[1] . "\\" . $sNextFileName;
  205.     }
  206. }
  207.  
  208. ///////////////////////////////////////////////////
  209. // Make sure that we have a valid fileNum passed in.
  210. ///////////////////////////////////////////////////
  211. if ($errorOccurred == 0)
  212. {
  213.     if (!isset($_GET['fileNum']))
  214.     {
  215.         $errorOccurred = 202;
  216.         log_activity("QS check", "failure", return_error_text(202, "", $arErrors));
  217.     }
  218.     else
  219.     {
  220.         $fileNum = intval($_GET['fileNum']);
  221.         if ($fileNum > $count)
  222.         {
  223.             // if we have a number greater than the count, assume they tried to wrap around the end
  224.             $fileNum = $count;
  225.         }
  226.         if ($fileNum < 1 )
  227.         {
  228.             // if we have a number less than 1, assume they tried to wrap around the start
  229.             $fileNum = 1;
  230.         }
  231.     }
  232. }
  233. ///////////////////////////////////////////////////
  234. // make sure the file requested actually exists
  235. ///////////////////////////////////////////////////
  236. if (!file_exists($sFullFilePath))
  237. {
  238.     log_activity("get file details", "error", return_error_text(342, "", $arErrors));
  239.     gotoAbs('/error/342/return');
  240. }
  241.  
  242. ///////////////////////////////////////////////////
  243. // start printing out the HTML to the browser
  244. ///////////////////////////////////////////////////
  245. require "_header.php";
  246. require "_cookie_util.php";
  247.  
  248. $detailslink    =   "/filedetails/" . $sShare . "/" . urlEncodeString($sFullFilePath);
  249. $backlink       =   "/fileview/" . $sShare . "/" . urlEncodeString($sPrevFilePath)
  250.                     . "/" . urlEncodeString($sPrevFileName) . "&fileNum=" . ($fileNum - 1);
  251. $nextlink       =   "/fileview/" . $sShare . "/" . urlEncodeString($sNextFilePath)
  252.                     . "/" . urlEncodeString($sNextFileName) . "&fileNum=" . ($fileNum + 1);
  253.  
  254. $iFileNamePos   = strpos($sFullFilePath, strrchr($sFullFilePath, "\\"));
  255. $sFile          = substr($sFullFilePath, $iFileNamePos+1);
  256. $sPathNoFile    = substr($sFullFilePath, 0, (strlen($sFullFilePath) - strlen($sFile) - 1));
  257. $viewlink         = "/fileopen/" . $sShare . "/" . urlEncodeString($sPathNoFile) . "/" . urlEncodeString($sFile);
  258. $folderlink     = "/folderview/" . $sShare . "/" . urlEncodeString($sFullFilePath);
  259. $downloadlink     = "/filesave/" . $sShare . "/" . urlEncodeString($sPathNoFile) . "/" . urlEncodeString($sFile);
  260. $detailsviewimage = "/detailsview/" . $sShare . "/" . urlEncodeString($sPathNoFile) . "/" . urlEncodeString($sFile);
  261.  
  262. $bIsDir = (is_dir($sFullFilePath) && ($sFile != ".") && ($sFile != ".."));
  263.  
  264. $sFileExtension = strtolower(strrchr($sFile, "."));
  265. $bSupportedExtension = true;
  266. if (isValidString($sFileExtension))
  267. {
  268.     $bSupportedExtension = isSupportedDownloadExtension($sDownloadUnsupportedExtensions, $sFileExtension);
  269. }
  270. ?>
  271.     <table cellspacing="0" cellpadding="0" border="0" width="100%">
  272.         <tr>
  273.             <td width="100%" valign="top">
  274.                 <?php require "_public_error_states.php"; ?>
  275.                 <!-- Start Folder view table -->
  276.                     <table cellspacing="0" cellpadding="0" border="0" class="ContentTable"> 
  277.                         <tr>
  278.                             <td class="ContentTableTL"><div> </div></td>
  279.                             <?php printBreadcrumbs($sShare, $sUnc, $sFullFilePath, $sContainer, $iBreadCrumbDetailsTruncateLength, $count, $ObjectsPerPage, ceil($fileNum/$ObjectsPerPage), true); ?>
  280.                             <td class="ContentTableTM3">
  281.                                 <?php
  282.                                 if ($bShowNextPrev)
  283.                                 {
  284.                                 ?>
  285.                                 <table cellspacing="0" cellpadding="0" border="0" align="right" class="NextPrevButtonContain">
  286.                                     <tr>
  287.                                         <td><a href="<?php echo ($backlink); ?>"><span class="PrevPicture" title="Show Previous Item..." onMouseOver="this.className='PrevPictureOver'" onMouseOut="this.className='PrevPicture'"></span></a></td>
  288.                                         <td><a href="<?php echo ($nextlink); ?>"><span class="NextPicture" title="Show Next Item..." onMouseOver="this.className='NextPictureOver'" onMouseOut="this.className='NextPicture'"></span></a></td>
  289.                                     </tr>
  290.                                 </table>
  291.                                 <?php
  292.                                 }
  293.                                 else
  294.                                 {
  295.                                     echo (" ");
  296.                                 }
  297.                                 ?>
  298.                             </td>
  299.                             <td class="ContentTableTR"><div> </div></td>
  300.                         </tr>
  301.                         <tr>
  302.                             <td class="ContentTableML"><div> </div></td>
  303.                             <td class="ContentTableMM" colspan="3">
  304.                                 <div class="ShareContents MidSizeImage" style="text-align:center;">
  305. <?php
  306. if (!$bIsDir)
  307. {
  308.     if ($bSupportedExtension)
  309.     {
  310. ?>
  311. <a href="<?php echo ($viewlink); ?>" target="_new">
  312. <img class="MidSizeImg<?php echo $imgMode; ?>" src="<?php echo ($detailsviewimage); ?>"  alt="<?php echo(substr(strrchr($sFullFilePath,"\\"),1)); ?>" border=0/>
  313. </a>
  314. <?php
  315.     }
  316.     else
  317.     {
  318. ?>
  319. <img class="MidSizeImg<?php echo $imgMode; ?>" src="<?php echo ($imgLocation); ?>"  <?php if (isset($imageTag_width)) {echo ("width=\"" . $imageTag_width . "\"");} ?> <?php if (isset($imageTag_height)) {echo ("height=\"" . $imageTag_height . "\"");} ?> alt="<?php echo(substr(strrchr($sFullFilePath,"\\"),1)); ?>" border=0/>
  320. <?php
  321.     }
  322. }
  323. else
  324. {
  325. ?>
  326. <div class="MidSizeImgFolder">
  327.         <div>
  328.         <div class="MidSizeImgFolderImage" onclick="location.href='<?php echo ($folderlink); ?>'"> </div>
  329.         </div>
  330. </div>
  331. <br/><br/>
  332. <?php
  333. }
  334. ?>
  335.                                 </div> <!--ShareContents-->
  336.                             </td>
  337.                             <td class="ContentTableMR"> </td>
  338.                         </tr>
  339.                         <tr>
  340.                             <td class="ContentTableBL"> </td>
  341.                             <td class="ContentTableBM" colspan="3"> </td>
  342.                             <td class="ContentTableBR"> </td>
  343.                         </tr>
  344.                     </table> <!-- End Folder View Table -->
  345.                 </td>
  346.                 <td valign="top">
  347. <?php
  348. ///////////////////////////////////////////////////
  349. // Define the tasks for this page
  350. ///////////////////////////////////////////////////
  351. $iTaskCount = 0;
  352. if ($arSharePath[3]) // this is the slideshow true or false information
  353. {
  354.     $arTasks[$iTaskCount][0] = "View slideshow";
  355.     $arTasks[$iTaskCount][1] = "javascript:openSlideshow('/slideshow/" . $sShare . "/" . urlEncodeString($sPathNoFile) . "/');";
  356.     $arTasks[$iTaskCount][2] = "SlideshowLink";
  357.     $arTasks[$iTaskCount][3] = "";
  358.     $iTaskCount++;
  359. }
  360.  
  361. ///////////////////////////////////////////////////
  362. // Force files with specific extensions to behave
  363. // specific ways regardless of requested action
  364. ///////////////////////////////////////////////////
  365. if ($bSupportedExtension)
  366. {
  367.     if (!$bIsDir)
  368.     {
  369.         switch ($sFileExtension)
  370.         {
  371.             case ".exe":
  372.                 $arTasks[$iTaskCount][0] = "Open file";
  373.                 $arTasks[$iTaskCount][1] = $viewlink;
  374.                 $arTasks[$iTaskCount][2] = "OpenFileLink";
  375.                 $arTasks[$iTaskCount][3] = "_new";
  376.                 $iTaskCount++;
  377.                 break;
  378.             default:
  379.                 $arTasks[$iTaskCount][0] = "Open file";
  380.                 $arTasks[$iTaskCount][1] = $viewlink;
  381.                 $arTasks[$iTaskCount][2] = "OpenFileLink";
  382.                 $arTasks[$iTaskCount][3] = "_new";
  383.                 $iTaskCount++;
  384.         }
  385.         $arTasks[$iTaskCount][0] = "Download file";
  386.         $arTasks[$iTaskCount][1] = $downloadlink;
  387.         $arTasks[$iTaskCount][2] = "SaveFileLink";
  388.         $arTasks[$iTaskCount][3] = "_new";
  389.         $iTaskCount++;
  390.     }
  391.     else
  392.     {
  393.                 $arTasks[$iTaskCount][0] = "Open folder";
  394.                 $arTasks[$iTaskCount][1] = $folderlink;
  395.                 $arTasks[$iTaskCount][2] = "OpenFolderLink";
  396.                 $arTasks[$iTaskCount][3] = "";
  397.                 $iTaskCount++;
  398.     }
  399. }
  400.  
  401.  
  402. $bLimitLocations = true;
  403. require "panels.php";
  404. ?>
  405.  
  406.                 </td>
  407.             </tr>
  408.         </table>
  409. <script type="text/javascript">
  410.     writePrepCookie();
  411. </script>
  412. <?php 
  413. ///////////////////////////////////////////////////
  414. // Finish printing out the HTML to the browser
  415. ///////////////////////////////////////////////////
  416. require "_footer.php";
  417.  ?>
  418.